
import absdragsvc from "./absdragsvc";
import LXCOM from '../../common/common.js'
import utilfuncs from "../../common/tools/utilfuncs";
var funcs = utilfuncs.UtilFuncs;
import globalConst from "../../common/globalConst";
var global = globalConst.GlobalConst;

class LineDragDropSvc extends absdragsvc.AbsDragSvc {
    assignProp(worldPos, mapscale) {
        console.log("LineDragDropSvc");
        var position = this.graph.getPos();

        let isTwoPtLine = true;
        let unitLinePtList = null;
        let symbol = this.graph.getSymbol();
        if (symbol) {
            let symbolUnitList = symbol.getSymbolUnitLst();
            if (symbolUnitList && symbolUnitList.length == 1){
                let lineUnit = symbolUnitList[0];
                if (funcs.mainObjType(lineUnit.type) == global.BaseUnitPolyline){
                    unitLinePtList = lineUnit.pos.posList;
                    if (unitLinePtList.length > 2){
                        isTwoPtLine = false;
                    }
                    else{
                        unitLinePtList = null;
                    }
                }
            }
        }

        if (isTwoPtLine || !unitLinePtList) {
            let wid = 100;
            var p1 = new LXCOM.LGXPoint();
            p1.x = worldPos.x - wid;
            p1.y = worldPos.y;

            var p2 = new LXCOM.LGXPoint();
            p2.x = worldPos.x + wid;
            p2.y = worldPos.y;

            position.posList.push(p1);
            position.posList.push(p2);
        }
        else{
            unitLinePtList.forEach(pt => {
                let newPt = {x:0,y:0};
                newPt.x = worldPos.x + pt.x;
                newPt.y = worldPos.y + pt.y;
                position.addPoint(newPt);
            });
        }

    }
}
export default { LineDragDropSvc }